// components/index/banner/banner.js
const app = getApp()
Component({
  /**
   * 组件的属性列表
   */
  properties: {
    
  },
  
  /**
   * 组件的初始数据
   */
  data: {
    username: '',
    id: -1,
    avatarUrl: '',
    bannerUrl: 'https://6d79-my-book-assist-7gc4zqa8552557ed-1305224861.tcb.qcloud.la/images/banners/banner3.jpg',
    isLogin: false
  },
  
  lifetimes: {
    async attached () {
      const getUserInfo = (globalData) => {
        return new Promise((resolve, reject) => {
          const clock = setInterval(() => {
            if (globalData.userInfo && typeof globalData.userInfo.fresh !== 'undefined') {
              resolve(globalData.userInfo)
              clearInterval(clock)
            }
          }, 100)
        }).then (res => {
          this.setData({
            username: res.username,
            avatarUrl: res.avatarUrl,
            id: res._id,
            fresh: res.fresh,
            isLogin: true
          })
        })
      }
      await getUserInfo(app.globalData)
    },
  },

  /**
   * 组件的方法列表
   */
  methods: {
    getUserProfile () {
      wx.navigateTo({
        url: '/pages/login/login'
      })
    }
  }
})
